package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.AdminOrderMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
//@Component
@RequiredArgsConstructor
public class OrderTask {

    private final AdminOrderMapper adminOrderMapper;

    @Scheduled(cron = "0/5 * * * * ?")
    public void OrderTask(){
        log.info("------------执行开始-------------");
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime plusMinTime = now.plusMinutes(-1L);
        Integer count = adminOrderMapper.updateStatusByPayStatusAndOrderTime(Orders.CANCELLED,Orders.UN_PAID,Orders.PENDING_PAYMENT,plusMinTime);
        log.info("------------执行结束  |  执行了{}条-------------" ,count);
    }

    @Scheduled(cron = "0/5 * * * * ?")
    public void completeOrder(){
        log.info("------------执行开始-------------");
        Integer count = adminOrderMapper.updateStatusByStatus(Orders.COMPLETED , Orders.DELIVERY_IN_PROGRESS);
        log.info("------------执行结束  |  执行了{}条-------------" ,count);
    }
}
